package com.fotoloka.view;

import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JComponent;

@SuppressWarnings("serial")
public class Botao extends JButton {

	private boolean centralizado = true;
	
	private Integer distancia;

	private JComponent parent;
	
	public Botao(JComponent parent, String texto) {
		this.setText(texto);
		this.parent = parent;
	}

	public Botao(JComponent parent, String texto, boolean centralizado) {
		this(parent, texto);
		this.centralizado = centralizado;
	}
	
	public Botao(JComponent parent, String texto, boolean centralizado, int distancia) {
		this(parent, texto);
		this.centralizado = centralizado;
		this.distancia = distancia;
	}

	@Override
	protected void paintComponent(Graphics g) {
		
		
		if (centralizado) {

			int width = this.getWidth(); 
			int height = this.getHeight();

			int x = (parent.getWidth() - width) / 2;
			
			int y = (parent.getHeight() - height) /2;
			if(distancia != null) {
				y = (parent.getHeight() - height + distancia) /2;
			}
			
			this.setBounds(x, y, width, height);
			
		}
		
		super.paintComponent(g);
	}

}
